<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">订单号：<b>{{ $order->number }}</b></h3>
        <div class="box-tools">
            <div class="btn-group float-right" style="margin-right: 10px">
                <a href="{{ route('admin.orders.index') }}" class="btn btn-sm btn-default"><i class="fa fa-list"></i> 列表</a>
            </div>
        </div>
    </div>
    <div class="box-body">
        <table class="table table-bordered">
            <tr>
                <td>会员：<b>{{ $order->user->name }}</b></td>
            </tr>
        </table>
        <hr>
        <table class="table table-bordered">
            <tr>
                <td>
                    支付时间：
                    @if($order->isPaid())
                        <b>{{ (string)$order->paid_at }}</b>
                    @else
                        <span class="label label-danger">未支付</span>
                    @endif
                </td>
                <td>
                    支付方式：
                    @if($order->isPaid())
                        <b>{{ config("site.payment.methods.{$order->paid_method}") }}:{{ $order->paid_number }}</b>
                    @else
                        <span class="label label-danger">未支付</span>
                    @endif
                </td>
            </tr>
        </table>
        <hr>
        <table class="table table-bordered">
            <tr>
                <td>收货地址</td>
                <td colspan="3">
                    <b>
                        {{ $order->address['address'] }}
                        {{ $order->address['contact_name'] }}
                        {{ $order->address['contact_phone'] }}
                    </b>
                </td>
            </tr>
        </table>
        <hr>
        <table class="table table-bordered">
            <tr>
                <td rowspan="{{ $order->items->count() + 1 }}">商品列表</td>
                <td>商品名称</td>
                <td>成交价</td>
                <td>数量</td>
            </tr>
            @foreach($order->items as $item)
                <tr>
                    <td>
                        <b>
                            ({{ $item->product_id }}): {{ $item->product_title }}
                            <a href="{{ route('admin.products.edit', $item->product_id) }}">
                                <i class="fa fa-arrow-circle-left"></i>
                            </a>
                        </b>
                        ({{ $item->product_sku_id }}): <b>{{ $item->sku_name }}</b>
                        @if($item->sku_attr_value)
                            @foreach($item->sku_attr_value as $value)
                                <span style="font-size:10px">[{{ $value }}]</span>
                            @endforeach
                        @endif
                        <a href="{{ route('admin.product-skus.edit', $item->product_id) }}">
                            <i class="fa fa-arrow-circle-left"></i>
                        </a>
                    </td>
                    <td>￥<b>{{ $item->price }}</b></td>
                    <td><b>{{ $item->amount }}</b></td>
                </tr>
            @endforeach
        </table>
        <hr>
        <table class="table table-bordered">
            <tr>
                <td>订单总额：￥<b>{{ $order->total_amount }}</b></td>
            </tr>
        </table>
        <hr>
        <table class="table table-bordered">
            <!-- delivery -->
            <tr>
                <td>
                    物流状态：
                    @if(!$order->paid_at)
                        <span class="label label-danger">待付款</span>
                    @elseif($order->delivery_status === 'pending')
                        <span class="label label-default">
                            {{ config("site.order.delivery_status.{$order->delivery_status}") }}
                        </span>
                    @elseif($order->delivery_status === 'delivered')
                        <span class="label label-info">
                            {{ config("site.order.delivery_status.{$order->delivery_status}") }}
                        </span>
                    @elseif($order->delivery_status === 'received')
                        <span class="label label-success">
                            {{ config("site.order.delivery_status.{$order->delivery_status}") }}
                        </span>
                    @endif
                </td>
            </tr>
        </table>
        <form action="{{ route('admin.orders.deliver', [$order->id]) }}" method="post" class="form-inline">{{ csrf_field() }}
            <table class="table table-bordered">
                <tr>
                    <td>
                        <div class="form-group {{ $errors->has('delivery_company') ? 'has-error' : '' }}">
                            <label for="delivery_company" class="control-label">物流公司</label>
                            <select name="delivery_company" id="delivery_company" class="form-control">
                                @foreach(config('express.companies') as $code => $company)
                                    <option value="{{ $code }}">{{ $company }}</option>
                                @endforeach
                            </select>
                            @if($errors->has('delivery_company'))
                                @foreach($errors->get('delivery_company') as $message)
                                    <span class="help-block">{{ $message }}</span>
                                @endforeach
                            @endif
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="form-group {{ $errors->has('delivery_number') ? 'has-error' : '' }}">
                            <label for="delivery_number" class="control-label">&nbsp;物流单号</label>
                            <input type="text" id="delivery_number" name="delivery_number" value="" class="form-control" placeholder="输入物流单号">
                            @if($errors->has('delivery_number'))
                                @foreach($errors->get('delivery_number') as $message)
                                    <span class="help-block">{{ $message }}</span>
                                @endforeach
                            @endif
                        </div>
                        <button type="submit" class="btn btn-success" id="ship-btn">发货</button>
                    </td>
                </tr>
            </table>
        </form>
    
        <table class="table table-bordered">
            <tr>
                <td colspan="2">物流公司：{{ $order->delivery_data ? config("express.companies.{$order->delivery_data['delivery_company']}") : '' }}</td>
            </tr>
            <tr>
                <td colspan="2">物流单号：{{ $order->delivery_data ? $order->delivery_data['delivery_number'] : '' }}</td>
            </tr>
            @if($order->delivery_status !== 'pending')
                <tr>
                    <td>
                        <ul>
                            <li><b>跟踪...</b></li>
                            @if(isset($express['data']) and count($express['data']) > 0)
                                @foreach($express['data'] as $datum)
                                    <li style="margin-top: 15px">
                                        {{ $datum['time'] }}{{ $datum['context'] }}{{ $datum['status'] }}
                                    </li>
                                @endforeach
                            @else
                                <li>暂无数据...</li>
                            @endif
                        </ul>
                    </td>
                </tr>
            @endif
        </table>
        <!-- delivery -->
        
    </div>
</div>
